<?php
class sqlop{
	public static function getconnection(){
		$dbhost ="rm-8vb31843068k2bxiz.mysql.zhangbei.rds.aliyuncs.com";
		$dbuser = "chuwugui_root";
		$dbpwd = "Chuwugui@ddfdfs";
		$dbname = "chuwugui";
		$charName = "gbk2312";
		$mysqliobj = new mysqli($dbhost,$dbuser,$dbpwd,$dbname);
		if(mysqli_connect_errno()){
			echo "连接失败：".mysqli_connect_error();
			return null;
		}
		$mysqliobj->query("set names utf8");
		return $mysqliobj;
	}
	public static function query($sqlstr){
		$mysqliobj = sqlop::getconnection();
		if(empty($mysqliobj)) return -1;
		$mysqliobj->query($sqlstr);
		$ret=$mysqliobj->affected_rows;
		$mysqliobj->close();
		return $ret;
	}
	public static function insert($sqlstr){
		$mysqliobj = sqlop::getconnection();
		if(empty($mysqliobj)) return -1;
		$mysqliobj->query("insert ".$sqlstr);
		$ret=$mysqliobj->affected_rows;
		$mysqliobj->close();
		return $ret;
	}
	public static function update($sqlstr){
		$mysqliobj = sqlop::getconnection();
		if(empty($mysqliobj)) return -1;
		$mysqliobj->query("update ".$sqlstr);
		$ret=$mysqliobj->affected_rows;
		$mysqliobj->close();
		return $ret;
	}
	public static function delete($sqlstr){
		$mysqliobj = sqlop::getconnection();
		if(empty($mysqliobj)) return -1;
		$mysqliobj->query("delete from ".$sqlstr);
		$ret=$mysqliobj->affected_rows;
		$mysqliobj->close();
		return $ret;
	}
	public static function select($sqlstr){
		$mysqliobj = sqlop::getconnection();
		if(empty($mysqliobj)) return -1;
		$result=$mysqliobj->query("select ".$sqlstr);
		$mysqliobj->close();
		return $result;
	}
}
?>